package com.zero.logistics.mapper;

import com.zero.logistics.pojo.Order;
import com.zero.logistics.pojo.OrderExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface OrderMapper {
    @Delete({
        "delete from t_order",
        "where order_id = #{orderId,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long orderId);

    @Insert({
        "insert into t_order (order_id, user_id, ",
        "customer_id, shipping_address, ",
        "shipping_name, shipping_phone, ",
        "take_name, take_address, ",
        "take_phone, order_status, ",
        "payment_method_id, region_id, ",
        "take_method_id, freight_method_id, ",
        "order_remark)",
        "values (#{orderId,jdbcType=BIGINT}, #{userId,jdbcType=BIGINT}, ",
        "#{customerId,jdbcType=BIGINT}, #{shippingAddress,jdbcType=VARCHAR}, ",
        "#{shippingName,jdbcType=VARCHAR}, #{shippingPhone,jdbcType=VARCHAR}, ",
        "#{takeName,jdbcType=VARCHAR}, #{takeAddress,jdbcType=VARCHAR}, ",
        "#{takePhone,jdbcType=VARCHAR}, #{orderStatus,jdbcType=INTEGER}, ",
        "#{paymentMethodId,jdbcType=BIGINT}, #{regionId,jdbcType=BIGINT}, ",
        "#{takeMethodId,jdbcType=BIGINT}, #{freightMethodId,jdbcType=BIGINT}, ",
        "#{orderRemark,jdbcType=VARCHAR})"
    })
    @Options(keyColumn="order_id", keyProperty="orderId", useGeneratedKeys=true)
    int insert(Order record);

    @InsertProvider(type=OrderSqlProvider.class, method="insertSelective")
    int insertSelective(Order record);

    @SelectProvider(type=OrderSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="order_id", property="orderId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT),
        @Result(column="customer_id", property="customerId", jdbcType=JdbcType.BIGINT),
        @Result(column="shipping_address", property="shippingAddress", jdbcType=JdbcType.VARCHAR),
        @Result(column="shipping_name", property="shippingName", jdbcType=JdbcType.VARCHAR),
        @Result(column="shipping_phone", property="shippingPhone", jdbcType=JdbcType.VARCHAR),
        @Result(column="take_name", property="takeName", jdbcType=JdbcType.VARCHAR),
        @Result(column="take_address", property="takeAddress", jdbcType=JdbcType.VARCHAR),
        @Result(column="take_phone", property="takePhone", jdbcType=JdbcType.VARCHAR),
        @Result(column="order_status", property="orderStatus", jdbcType=JdbcType.INTEGER),
        @Result(column="payment_method_id", property="paymentMethodId", jdbcType=JdbcType.BIGINT),
        @Result(column="region_id", property="regionId", jdbcType=JdbcType.BIGINT),
        @Result(column="take_method_id", property="takeMethodId", jdbcType=JdbcType.BIGINT),
        @Result(column="freight_method_id", property="freightMethodId", jdbcType=JdbcType.BIGINT),
        @Result(column="order_remark", property="orderRemark", jdbcType=JdbcType.VARCHAR)
    })
    List<Order> selectByExample(OrderExample example);

    @Select({
        "select",
        "order_id, user_id, customer_id, shipping_address, shipping_name, shipping_phone, ",
        "take_name, take_address, take_phone, order_status, payment_method_id, region_id, ",
        "take_method_id, freight_method_id, order_remark",
        "from t_order",
        "where order_id = #{orderId,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="order_id", property="orderId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT),
        @Result(column="customer_id", property="customerId", jdbcType=JdbcType.BIGINT),
        @Result(column="shipping_address", property="shippingAddress", jdbcType=JdbcType.VARCHAR),
        @Result(column="shipping_name", property="shippingName", jdbcType=JdbcType.VARCHAR),
        @Result(column="shipping_phone", property="shippingPhone", jdbcType=JdbcType.VARCHAR),
        @Result(column="take_name", property="takeName", jdbcType=JdbcType.VARCHAR),
        @Result(column="take_address", property="takeAddress", jdbcType=JdbcType.VARCHAR),
        @Result(column="take_phone", property="takePhone", jdbcType=JdbcType.VARCHAR),
        @Result(column="order_status", property="orderStatus", jdbcType=JdbcType.INTEGER),
        @Result(column="payment_method_id", property="paymentMethodId", jdbcType=JdbcType.BIGINT),
        @Result(column="region_id", property="regionId", jdbcType=JdbcType.BIGINT),
        @Result(column="take_method_id", property="takeMethodId", jdbcType=JdbcType.BIGINT),
        @Result(column="freight_method_id", property="freightMethodId", jdbcType=JdbcType.BIGINT),
        @Result(column="order_remark", property="orderRemark", jdbcType=JdbcType.VARCHAR)
    })
    Order selectByPrimaryKey(Long orderId);

    @UpdateProvider(type=OrderSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Order record);

    @Update({
        "update t_order",
        "set user_id = #{userId,jdbcType=BIGINT},",
          "customer_id = #{customerId,jdbcType=BIGINT},",
          "shipping_address = #{shippingAddress,jdbcType=VARCHAR},",
          "shipping_name = #{shippingName,jdbcType=VARCHAR},",
          "shipping_phone = #{shippingPhone,jdbcType=VARCHAR},",
          "take_name = #{takeName,jdbcType=VARCHAR},",
          "take_address = #{takeAddress,jdbcType=VARCHAR},",
          "take_phone = #{takePhone,jdbcType=VARCHAR},",
          "order_status = #{orderStatus,jdbcType=INTEGER},",
          "payment_method_id = #{paymentMethodId,jdbcType=BIGINT},",
          "region_id = #{regionId,jdbcType=BIGINT},",
          "take_method_id = #{takeMethodId,jdbcType=BIGINT},",
          "freight_method_id = #{freightMethodId,jdbcType=BIGINT},",
          "order_remark = #{orderRemark,jdbcType=VARCHAR}",
        "where order_id = #{orderId,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Order record);

    @DeleteProvider(type=OrderSqlProvider.class, method="deleteByIds")
	int deleteByIds(@Param("ids") String[] ids);
}